package codeTop;

/**
 * q112
 *
 * @author 雨凡
 * @version q112.java, v0.1
 * @date 2025/07/01/22:43
 */
public class q112 {
    public boolean hasPathSum(TreeNode root, int targetSum) {
        if (root == null) {
            return false;
        }
        dfs(root, targetSum);
        return flag;
    }

    private void dfs(TreeNode node, int targetSum) {
        if (flag) {
            return;
        }
        if (node.left == null && node.right == null) {
            if (targetSum == node.val) {
                flag = true;
            }
            return;
        }
        if (node.left != null) {
            dfs(node.left,targetSum- node.val);
        }
        if (node.right != null) {
            dfs(node.right,targetSum- node.val);
        }
    }

    boolean flag = false;
}
